home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9843 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help !!!!! on 'strstr"
  5. Date: Wed, 13 Mar 96 20:17:21 GMT
  6. Organization: none
  7. Distribution: world
  8. Message-ID: <826748241snz@genesis.demon.co.uk>
  9. References: <314703FF.4045@msmail.st.stems.com> <TANMOY.96Mar13090728@qcd.lanl.gov>
  10. Reply-To: fred@genesis.demon.co.uk
  11. X-NNTP-Posting-Host: genesis.demon.co.uk
  12. X-Newsreader: Demon Internet Simple News v1.27
  13. X-Mail2News-Path: genesis.demon.co.uk
  14.  
  15. In article <TANMOY.96Mar13090728@qcd.lanl.gov>
  16.            tanmoy@qcd.lanl.gov "Tanmoy Bhattacharya" writes:
  17.  
  18. >On a side issue, is anybody aware of a real locale where, given
  19. >unsigned chars c1 and c2,
  20. >
  21. > (toupper(c1) == toupper(c2)) || (tolower(c1) == tolower(c2))
  22. >
  23. >is better than 
  24. >
  25. >  toupper(c1) == toupper(c2)
  26. >
  27. >? (I am reasonably sure that I do not want to check whether
  28. >toupper(tolower(x))'s match, but I always wondered about this one.)
  29.  
  30. I believe tolower(c1) == tolower(c2) (all arguments apply equivalently to
  31. toupper).
  32.  
  33. 7.3.2.1 The tolower function
  34.  
  35. "If the argument is a character for which isupper is true and there is a
  36.  corresponding character for which islower is true, the tolower function
  37.  returns the corresponding character; otherwise, the argument is returned
  38.  unchanged."
  39.  
  40. The determining factor is whether in this context 'corresponds' is
  41. a commutative relation. If so (and I believe that is implicit in its meaning)
  42. then tolower(x) is guaranteed to be the same as tolower(toupper(x)). There
  43. are curious cases possible i.e.
  44.  
  45. 1. An uppercase character has no corresponding lowercase value.
  46.  
  47. 2. A lowercase character has no corresponing uppercase value.
  48.  
  49. 3. A character is both uppercase and lowercase.
  50.  
  51. However in all of these cases neither toupper() nor tolower() can change
  52. the character. The 'normal' cases (i.e. those found in the "C" locale) are:
  53.  
  54. 4. A character is neither uppercase nor lowercase
  55.  
  56. Again toupper() and tolower() must leave this unchanged.
  57.  
  58. 5. A 'corresponding' pair of characters exists where one is uppercase only
  59.    and the other is lowercase only.
  60.  
  61. Given one of these characters toupper() and tolower() can only map it to
  62. itself or to the corresponding one. The function used determines which you
  63. get out irrespective of which you give it. Therefore in a sequence of
  64. toupper/tolower mappings only the last one executed can affect the
  65. final result.
  66.  
  67. -- 
  68. -----------------------------------------
  69. Lawrence Kirby | fred@genesis.demon.co.uk
  70. Wilts, England | 70734.126@compuserve.com
  71. -----------------------------------------
  72.